{% extends "base/base.html" %}

{% block content %}
<div class="panel panel-default">
  <div class="panel-heading">导航条管理</div>
  <div class="panel-body" id="tab">
    <div class="alert alert-danger" style="display: none;" role="alert">
      <strong>错误 </strong><span></span>
    </div>

    <form class="form-horizontal" method="post" action="/manage/tabs">
      <input name="type" type="hidden" value="tab">
      <div class="form-group">
        <label for="name" class="col-sm-2 control-label">导航条</label>
        <div class="col-sm-4">
          <input type="text" class="form-control" id="name" name="name">
        </div>
      </div>
      <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
          <button type="submit" class="btn btn-default">添加</button>
        </div>
      </div>
    </form>
  </div>
</div>
<div class="panel panel-default">
  <div class="panel-heading">标签管理</div>
  <div class="panel-body">
    <div class="alert alert-danger" style="display: none;" role="alert">
      <strong>错误 </strong><span></span>
    </div>

    <form class="form-horizontal" method="post" action="/manage/tabs">
      <input name="type" type="hidden" value="tag">
      <div class="form-group">
        <label for="nav" class="col-sm-2 control-label">导航</label>
        <div class="col-sm-4">
          <select class="form-control" id="nav" name="tab_id">
            {% for tab in tabs %}
            <option value="{{ tab.id }}">{{ tab.name }}</option>
            {% endfor %}
          </select>
        </div>
      </div>
      <div class="form-group">
        <label for="name" class="col-sm-2 control-label">标签</label>
        <div class="col-sm-4">
          <input type="text" class="form-control" id="name" name="name">
        </div>
      </div>
      <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
          <button type="submit" class="btn btn-default">添加</button>
        </div>
      </div>
    </form>
  </div>
</div>
<script type="text/javascript">
 $(document).ready(function () {
   $("form").each(function(){
      console.log(this);
      var form = this;
      $(this).find("button[type=submit]").click(function(){
        var data = {}
        $(form).find("[name]").each(function(){
          data[$(this).attr("name")] = $(this).val()
        })
        $.post($(form).attr("action"), data, function(response){
          if(response.ret == 20000){
            window.location.href = response.redirect
          }else{
            $(form).prev("div[role=alert]").css("display", "block")
            $(form).prev("div[role=alert]").html(response.msg)
          }
        }).error(function(){
            $(form).prev("div[role=alert]").css("display", "block")
            $(form).prev("div[role=alert]").html("系统错误")
        })
        console.log(data)
        return false
      })

   })
  });
</script>
{% endblock %}

{% block sidebar %}
{% include "sidebar/operations.html" %}
{% endblock %}